package com.neusoft.demo.controller;

import javax.servlet.http.HttpSession;

import org.omg.PortableInterceptor.USER_EXCEPTION;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.neusoft.demo.po.Admin;
import com.neusoft.demo.service.AdminService;

@Controller
public class AdminController {

	@Autowired AdminService adminService;
	@RequestMapping("login.action")
	public String login(String adminname,String passwd,Model model,HttpSession session) {
		
		Admin admin=adminService.findAdmin(adminname, passwd);
		if (admin!=null) {
			session.setAttribute("ADMIN_SESSION", admin);
			return "redirect:/user/userInfo";
			
		}
		model.addAttribute("msg","账号或者密码错误");
		return "adminlogin";
	}
	
	@RequestMapping("logout.action")
	public String logout(HttpSession session) {
		session.invalidate();
		return "redirect:tologin.action";
	}
	@RequestMapping("tologin.action")
	public String toLogin() {
		return "adminlogin";
	}
	
	/**
	 * 没有拦截器登录的情况下，
	 */
	/*@RequestMapping("toUser.action")
	public String toCustomer() {
		return "customer";
	}*/
	
	
}
